package com.example.exercise.feedback.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;

import com.example.exercise.feedback.vo.AppFeedbackReplyVO;
import com.example.exercise.feedback.dao.entity.AppFeedbackReplyEntity;
import com.example.exercise.feedback.dao.AppFeedbackReplyDAO;

/**
* 
*/
@Service
public class AppFeedbackReplyService {

    @Autowired
    private AppFeedbackReplyDAO appFeedbackReplyDAO;

    public List<AppFeedbackReplyVO> findByWhere(Page<?> page, AppFeedbackReplyVO appFeedbackReplyVO){
        List<AppFeedbackReplyVO> list = new ArrayList<>();
        List<AppFeedbackReplyEntity> list0 = appFeedbackReplyDAO.findByWhere(page, appFeedbackReplyVO);
        for (AppFeedbackReplyEntity appFeedbackReplyEntity : list0) {
            list.add(toAppFeedbackReplyVO(appFeedbackReplyEntity));
        }
        return list;
    }

    public AppFeedbackReplyVO findByKey(AppFeedbackReplyVO appFeedbackReplyVO){
        AppFeedbackReplyEntity appFeedbackReplyEntity = appFeedbackReplyDAO.findByKey(appFeedbackReplyVO);
        return toAppFeedbackReplyVO(appFeedbackReplyEntity);
    }

    public int insert(AppFeedbackReplyVO appFeedbackReplyVO){
        return appFeedbackReplyDAO.insert(toAppFeedbackReplyEntity(appFeedbackReplyVO));
    }

    public int updateByKey(AppFeedbackReplyVO appFeedbackReplyVO){
        return appFeedbackReplyDAO.updateByKey(toAppFeedbackReplyEntity(appFeedbackReplyVO));
    }

    public int deleteByKey(AppFeedbackReplyVO appFeedbackReplyVO){
        return appFeedbackReplyDAO.deleteByKey(appFeedbackReplyVO);
    }

    private AppFeedbackReplyVO toAppFeedbackReplyVO(AppFeedbackReplyEntity appFeedbackReplyEntity) {
        AppFeedbackReplyVO appFeedbackReplyVO = new AppFeedbackReplyVO();
                appFeedbackReplyVO.setId(String.valueOf(appFeedbackReplyEntity.getId()));
        appFeedbackReplyVO.setReplyType(String.valueOf(appFeedbackReplyEntity.getReplyType()));
        appFeedbackReplyVO.setReplyContext(appFeedbackReplyEntity.getReplyContext());
        appFeedbackReplyVO.setFeedbackId(String.valueOf(appFeedbackReplyEntity.getFeedbackId()));
        appFeedbackReplyVO.setAdminId(appFeedbackReplyEntity.getAdminId());

        return appFeedbackReplyVO;
    }

    private AppFeedbackReplyEntity toAppFeedbackReplyEntity(AppFeedbackReplyVO appFeedbackReplyVO) {
        AppFeedbackReplyEntity appFeedbackReplyEntity = new AppFeedbackReplyEntity();
                String id = appFeedbackReplyVO.getId();
        if(id != null) {
            appFeedbackReplyEntity.setId(Integer.parseInt(appFeedbackReplyVO.getId()));
        }
        String replyType = appFeedbackReplyVO.getReplyType();
        if(replyType != null) {
            appFeedbackReplyEntity.setReplyType(Integer.parseInt(appFeedbackReplyVO.getReplyType()));
        }
        appFeedbackReplyEntity.setReplyContext(appFeedbackReplyVO.getReplyContext());
        String feedbackId = appFeedbackReplyVO.getFeedbackId();
        if(feedbackId != null) {
            appFeedbackReplyEntity.setFeedbackId(Integer.parseInt(appFeedbackReplyVO.getFeedbackId()));
        }
        appFeedbackReplyEntity.setAdminId(appFeedbackReplyVO.getAdminId());

        return appFeedbackReplyEntity;
    }

}